package tool

import (
	"github.com/gin-gonic/gin"
	"github.com/mojocn/base64Captcha"
	"image/color"
)

type CaptchaResult struct {
	Id string `json:"id"`
	Base64blob string `json:"base64_64_blob"`
	VertifyValue string `json:"code"`
}



func GenerateCaptcha(c *gin.Context){
	//var store = base64Captcha.DefaultMemStore
	var CapStore base64Captcha.Store
	 mystore :=InitRedisStore()

	CapStore= mystore

	rgb:= color.RGBA{R: 0, G: 0, B: 0, A: 0}
	var font []string=[]string{"wqy-microhei.ttc"}
	driverString :=base64Captcha.NewDriverString(60,
		240,
		0,
		0,
		6,
		"1234567890qwertyuioplkjhgfdsazxcvbnm",
		 &rgb,
		font)
	Captcha:= base64Captcha.Captcha{
		Driver:driverString,
		Store: CapStore,
	}
	id,result,err:=Captcha.Generate()
	if err!=nil{
		Failed(c,"生成失败")
	}
	code:=CapStore.Get(id,false)

	captchaResult:=CaptchaResult{id,result,code}
	Success(c,map[string]interface{}{
		"captcha_result":captchaResult,
		"value":code,
	})
}